<?php
include_once "xAP-functions/webincludes.php";


if(substr($extradata["Category"],0,4)=="Cat-"){
	// just one source
	$sql="select a.Alias,s.StoryID,s.DateStamp,s.Title,s.URL,s.Body,s.TagList,a.SourceID,a.Category from 
			xAP_News_Story as s  INNER JOIN  xAP_News_Source as a ON
			a.SourceID=s.SourceID
			where a.Category='".dbesc(substr($extradata["Category"],4))."' 
			
			order by s.datestamp DESC limit 10";
	$results=dbquery($sql);
	$title=$results[0]["Category"]." News";
}
elseif(substr($extradata["Category"],0,4)=="SRC-"){
	// just one source
	$sql="select a.Alias,s.StoryID,s.DateStamp,s.Title,s.URL,s.Body,s.TagList,a.SourceID from 
			xAP_News_Story as s  INNER JOIN  xAP_News_Source as a ON
			a.SourceID=s.SourceID 
			where s.SourceID=".intval(substr($extradata["Category"],4))."
			order by s.datestamp DESC limit 10";
	$results=dbquery($sql);
	$title=$results[0]["Alias"]." News";
}
else
{
	$title="Latest News";
}


$script="
<script type=\"text/javascript\" >
$(document).ready(function(){
	LatestNewsUpdate".$widgetID."();
	setInterval('LatestNewsUpdate".$widgetID."()',60000);
});
function LatestNewsUpdate".$widgetID."(){	
	$(\"#LatestNewsUpdate".$widgetID."\").load(\"/".$config["modulefolder"]."/widget_LatestNews_data.php?id=".$extradata["Category"]."\");
}
</script>";
$body="<div class='boldtext' id='LatestNewsUpdate".$widgetID."'></div>";
echo LayoutWidget("widget_LatestNews",$title,$body,$widgetID,$script);

?>